package com.example.myworkers.controller;/*
 *编写者：段光映
 */

import com.example.myworkers.model.Party;
import com.example.myworkers.service.PartyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "Party")
@RestController
@RequestMapping("/party")
public class PartyController {
    @Autowired
    private PartyService partyService;
    @ApiOperation(value = "添加方法")
    @PostMapping("/addParty")
    @CrossOrigin
    public int addParty(@RequestBody Party party){
        System.out.println("进入添加方法");
        return partyService.insertParty(party);
    }
    @ApiOperation(value = "删除方法")
    @GetMapping("/deleteParty")
    public int deleteParty(int parno) {
        System.out.println("进入删除方法");
        int parvalue = 0;
        if (parno != 0) {
           Party party=new Party();
            party.setParno(parno);
            parvalue=partyService.deleteParty(party);
        }
        return parvalue;
    }
    @ApiOperation(value = "查找党员所有信息")
    @GetMapping("/getAll")
    public List<Party> selectAllParty(Party party){
        System.out.println("进入查询所有党员信息方法");
        List<Party> listparty=partyService.selectAllParty(party);
        return listparty;
    }
    @ApiOperation(value = "更新党员信息方法")
    @PutMapping("/UpdateParty")
    public int updateParty(Party party){
        System.out.println("进入更新党员信息方法");
        return partyService.updateParty(party);
    }
    @ApiOperation(value = "对党员信息的单条查询方法")
    @GetMapping()
    public Party selectParty(int parno){
        Party party=new Party();
        System.out.println("进入党员信息单条查询法");
        if (parno!=0){
            Party party1=new Party();
            party1.setParno(parno);
            party=partyService.selectParty(party1);
        }
        return party;
    }
}

